module.exports = function ($scope, $state, $resource, $modal, center_list, center_list2) {

	$scope.maxSize = '5';			//最多显示多少个按钮
    $scope.currentPage = '1';		//当前页码
	$scope.itemsPerPage = '10'		//每页显示几条

	//下拉菜单
	$scope.sel = {
		//服务编码下拉菜单
		'center_code': center_list2,
		//权限类型下拉菜单
		'auth_type': [
			{ 'label': '全部', value: '' },
			{ 'label': '管理侧', value: 'a' },
			{ 'label': '用户侧', value: 'u' }
		],
		//接口类型下拉菜单
		'type': [
			{ 'label': '全部', value: '' },
			{ 'label': '方法类接口', value: 'c' },
			{ 'label': 'XML类接口', value: 's' }
		]
	};

	//页面加载执行
	$scope.start = function (){
		$resource('/api/as/sc/sysfun/getList', {}, {}).save({}, function(res){
			if(res.errcode === 0){
				$scope.apiList = res.data.results;
				$scope.totalItems = res.data.totalRecord;
			}else{
				alert(res.errmsg);
			}
		});
	};
	$scope.start();

	//搜索
	$scope.search = function (){
		var para = {
            'pageNo': $scope.currentPage,
            'pageSize': $scope.itemsPerPage,
			'auth_type': $scope.search.auth_type.value,
			'center_code': $scope.search.center_code.value,
			'type': $scope.search.type.value,
			'url': $scope.search.url,
		};
		$resource('/api/as/sc/sysfun/getList', {}, {}).save(para, function(res){
			if(res.errcode === 0){
				$scope.apiList = res.data.results;
				$scope.totalItems = res.data.totalRecord;
			}else{
				alert(res.errmsg);
			}
		});
	};

	//编辑接口
	$scope.edit = function (item) {
		$state.go('app.interfaceEdit', { 'id': item.id });
	};

	//接口参数
	$scope.param = function (item) {
		$state.go('app.interfaceParam', { 'id': item.id });
	};

	//设置权限
	$scope.authType = function (item) {
		var modalInstance = $modal.open({
			template: require('../views/authinfo.html'),
			controller: 'authInfo',
			size: 'lg',
			resolve: {
				items: function () {
					return item;
				}
			}
		});
		modalInstance.result.then(function() {
  			$scope.search();
		});
	};

	//接口参数
	$scope.getRole = function (item) {
		var modalInstance = $modal.open({
			template: require('../views/bindinfo.html'),
			controller: 'bindInfo',
			size: 'lg',
			resolve: {
				item: function () {
					return item;
				}
			}
		});
		modalInstance.result.then(function() {
  			
		});
	};

	//编辑接口
	$scope.setApi = function (item) {
		var modalInstance = $modal.open({
			template: require('../views/setbind.html'),
			controller: 'setBind',
			size: 'lg',
			resolve: {
				item: function () {
					return item;
				},
				center_list : function(interfaceservice){
					return interfaceservice.center_list();
				}
			}
		});
		modalInstance.result.then(function() {
  			
		});
	};

};